package com.hwqsdk.myapplication.practise;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;

/**
 * Create by Fanketly on 2021/11/24
 * Gitee:https://gitee.com/fanketly
 */
public class Picture {
    public static String take(Context context, String name) {
        String s = null;
        String selection = MediaStore.Images.Media.DISPLAY_NAME + "=?";
        Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                new String[]{MediaStore.Images.Media.DATA}, selection, new String[]{name}, null);
        if (cursor != null) {
            cursor.moveToFirst();
            cursor.moveToFirst();
            s = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
            cursor.close();
        }
        return s;
    }

    public static String pick(Context context, Uri uri) {
        String s;
        Cursor cursor = context.getContentResolver().query(uri, new String[]{MediaStore.Images.Media.DATA}, null
                , null, null);
        cursor.moveToFirst();
        s = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
        cursor.close();
        return s;
    }
}
